﻿using System;
using Aluetjen.EmailService.Domain.Gateways;
using Aluetjen.EmailService.Domain.Models.Message;
using AutoMapper;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Aluetjen.EmailService.Domain.SystemTests.Gateways
{
    [TestClass]
    public class SmtpGatewayTests
    {
        [TestMethod]
        public void MapMailMessage()
        {
            Mapper.AssertConfigurationIsValid();

            var message = new MailMessage("test@mailservice.com", "admin@luetjen.ie", "System Test", "Hello World! From Mapper Test");

            var smtpMailMessage = Mapper.Map<MailMessage, System.Net.Mail.MailMessage>(message);

            if (message.To != null)
                message.To.ForEach(i => smtpMailMessage.To.Add(Mapper.Map<MailAddress, System.Net.Mail.MailAddress>(i)));

            if( message.CC != null)
                message.CC.ForEach(i => smtpMailMessage.CC.Add(Mapper.Map<MailAddress, System.Net.Mail.MailAddress>(i)));

            if (message.Bcc != null)
                message.Bcc.ForEach(i => smtpMailMessage.Bcc.Add(Mapper.Map<MailAddress, System.Net.Mail.MailAddress>(i)));

            if (message.Attachments != null)
                message.Attachments.ForEach(i => smtpMailMessage.Attachments.Add(Mapper.Map<Attachment, System.Net.Mail.Attachment>(i)));

            Console.Write(smtpMailMessage);
        }

        [TestMethod]
        public void ProcessMessage()
        {
            var gateway = new SmtpGateway();
            var message = new MailMessage("test@mailservice.com", "admin@luetjen.ie", "System Test", "Hello World! From Mapper Test");

            gateway.Send(message);
        }
    }
}
